package cn.xfdzx.android.apps.shop.activity;


import android.app.Dialog;
import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Color;
import android.graphics.Point;
import android.net.Uri;
import android.os.Build;
import android.text.SpannableString;
import android.text.Spanned;
import android.text.style.ForegroundColorSpan;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewTreeObserver;
import android.view.animation.Animation;
import android.view.animation.CycleInterpolator;
import android.view.animation.ScaleAnimation;
import android.view.animation.TranslateAnimation;
import android.widget.AbsListView;
import android.widget.AdapterView;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.RadioButton;
import android.widget.RelativeLayout;
import android.widget.ScrollView;
import android.widget.TextView;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.widget.Toolbar;
import androidx.recyclerview.widget.DefaultItemAnimator;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.MultiTransformation;
import com.bumptech.glide.load.resource.bitmap.CenterCrop;
import com.bumptech.glide.load.resource.bitmap.RoundedCorners;
import com.bumptech.glide.request.RequestOptions;
import com.bumptech.glide.request.target.SimpleTarget;
import com.bumptech.glide.request.transition.Transition;
import com.google.android.material.appbar.AppBarLayout;
import com.google.gson.Gson;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonParser;
import com.luck.picture.lib.tools.ToastUtils;
import com.umeng.socialize.PlatformConfig;
import com.umeng.socialize.ShareAction;
import com.umeng.socialize.UMShareAPI;
import com.umeng.socialize.UMShareListener;
import com.umeng.socialize.bean.SHARE_MEDIA;
import com.umeng.socialize.media.UMImage;
import com.umeng.socialize.media.UMMin;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;

import butterknife.BindView;
import butterknife.OnClick;
import cn.xfdzx.android.apps.shop.R;
import cn.xfdzx.android.apps.shop.activity.login.OneLoginMainActivity;
import cn.xfdzx.android.apps.shop.activity.remake.ShopRemake_RetailActivity;
import cn.xfdzx.android.apps.shop.adapter.CarCouponsLVAdapter;
import cn.xfdzx.android.apps.shop.adapter.CarManJianLVAdapter;
import cn.xfdzx.android.apps.shop.adapter.ShopActivityAdapter;
import cn.xfdzx.android.apps.shop.adapter.ShopCarGoodsAdapter;
import cn.xfdzx.android.apps.shop.adapter.ShopRetailLeftLVAdapter;
import cn.xfdzx.android.apps.shop.adapter.ShopRetailRightAdapter;
import cn.xfdzx.android.apps.shop.adapter.remake.OrderMyRemake_RetailImageListAdapter;
import cn.xfdzx.android.apps.shop.apps.Constants;
import cn.xfdzx.android.apps.shop.base.BaseMvpActivity;
import cn.xfdzx.android.apps.shop.bean.BaseObjectBean;
import cn.xfdzx.android.apps.shop.bean.CarCouponsBeen;
import cn.xfdzx.android.apps.shop.bean.CarManJianBeen;
import cn.xfdzx.android.apps.shop.bean.ConfirmGoodBeen;
import cn.xfdzx.android.apps.shop.bean.HomeRetailBeen;
import cn.xfdzx.android.apps.shop.bean.MoreGoodsBean;
import cn.xfdzx.android.apps.shop.bean.ShopCarListBeen;
import cn.xfdzx.android.apps.shop.bean.ShopGoodListBeen;
import cn.xfdzx.android.apps.shop.bean.ShopRemakeListRetailBean;
import cn.xfdzx.android.apps.shop.bean.StoreInfoBeen;
import cn.xfdzx.android.apps.shop.bean.XFDGoodsDetailsBeen;
import cn.xfdzx.android.apps.shop.contract.GoodActionCallback;
import cn.xfdzx.android.apps.shop.contract.ItemClickListener;
import cn.xfdzx.android.apps.shop.contract.ShopRetailContract;
import cn.xfdzx.android.apps.shop.presenter.ShopRetailPresenter;
import cn.xfdzx.android.apps.shop.util.EmptyUtil;
import cn.xfdzx.android.apps.shop.util.ImageGlideUtil;
import cn.xfdzx.android.apps.shop.util.ItemOffsetDecoration;
import cn.xfdzx.android.apps.shop.util.PaletteHelper;
import cn.xfdzx.android.apps.shop.util.ProgressDialog;
import cn.xfdzx.android.apps.shop.util.RoundedFormation;
import cn.xfdzx.android.apps.shop.util.ShopCarPopupWindow;
import cn.xfdzx.android.apps.shop.util.StatusBarUtil;
import cn.xfdzx.android.apps.shop.util.Utils;
import cn.xfdzx.android.apps.shop.util.UtilsData;
import cn.xfdzx.android.apps.shop.video.VideoActivity;
import cn.xfdzx.android.apps.shop.view.MaxHeightRecyclerView;
import cn.xfdzx.android.apps.shop.view.ShoppingCartAnimationView;
import cn.xfdzx.android.apps.shop.view.SonicView;
import cn.xfdzx.android.apps.shop.widget.CornerImageView;

import static cn.xfdzx.android.apps.shop.apps.Constants.APP_TOKEN;
import static cn.xfdzx.android.apps.shop.apps.Constants.SHOPID_69_NO;

/**
 * 零售店铺页面
 */
public class ShopActivity extends BaseMvpActivity<ShopRetailPresenter> implements ShopRetailContract.View, GoodActionCallback {


    @BindView(R.id.ll_onclick_pack_up)
    LinearLayout llOnclickPackUp;
    @BindView(R.id.sv_shop_information)
    ScrollView svOnclickPackUp;
    @BindView(R.id.lv_menu_left)
    ListView lvMenuLeft;
    @BindView(R.id.rv_shop_goods)
    RecyclerView rvShopGoods;
    @BindView(R.id.tv_shop_goods_title_right)
    TextView tvTitleRight;
    @BindView(R.id.tv_business_hours_time)
    TextView tvBusinessHoursTime;
    @BindView(R.id.tv_month_sales)
    TextView tvMonthSales;
    @BindView(R.id.tv_info)
    TextView tvInfo;
    @BindView(R.id.tv_dayang)
    TextView tvDayang;
    @BindView(R.id.iv_shop_car)
    ImageView ivShopCar;
    @BindView(R.id.rl_shop_car)
    RelativeLayout rlShopCar;
    @BindView(R.id.rl_shop_bottom)
    RelativeLayout rlShopBottom;
    @BindView(R.id.tv_total_goods_num)
    TextView tvTotalGoodsNum;
    @BindView(R.id.ll_car)
    LinearLayout llCar;
    @BindView(R.id.view_bg_black)
    View viewBgBlack;
    @BindView(R.id.max_height_rv)
    MaxHeightRecyclerView maxHeightRv;
    @BindView(R.id.tv_to_settle_accounts)
    TextView tvToSettleAccounts;//去结算
    @BindView(R.id.rl_shop_search)
    RelativeLayout rlShopSearch;
    @BindView(R.id.tv_shop_phone)
    TextView tvShopPhone;
    @BindView(R.id.ll_led_securities)
    LinearLayout llLedSecurities;//购物车中弹窗中领劵;
    @BindView(R.id.view_shop_car_bg)
    View viewShopCarBg;
    @BindView(R.id.tv_shop_car_price)
    TextView tvShopCarPrice;
    @BindView(R.id.ll_state)
    LinearLayout llState;
    @BindView(R.id.ll_stateblack)
    LinearLayout ll_stateblack;
    @BindView(R.id.iv_shop_head)
    ImageView ivShopHead;
    @BindView(R.id.tv_shop_name)
    TextView tvShopName;
    @BindView(R.id.tv_introduce)
    TextView tvIntroduce;
    @BindView(R.id.tv_address)
    TextView tvAddress;
    @BindView(R.id.tv_car_total_num)
    TextView tvCarTotalNum;
    @BindView(R.id.tv_shop_car_hint)
    TextView tvShopCarHint;
    @BindView(R.id.tv_clear_all)
    TextView tvClearAll;
    @BindView(R.id.tv_activity_man_jian)
    TextView tvActivityManJian;
    @BindView(R.id.tv_activity)
    TextView tvActivity;
   @BindView(R.id.tv_youhui_num)
    TextView tvYouhuiNum;
    @BindView(R.id.view_title_bg)
    View viewTitleBg;
    @BindView(R.id.iv_shop_share)
    ImageView iv_shop_share;//分享店铺
    @BindView(R.id.iv_activity)
    ImageView ivActivity;
    @BindView(R.id.rv_activity)
    RecyclerView rvActivity;
    @BindView(R.id.rl_activity)
    RelativeLayout rlActivity;

    @BindView(R.id.sonic_view)
    SonicView sonicView;
    @BindView(R.id.rl_video_zhibo)
    RelativeLayout rlVideoZhibo;
    @BindView(R.id.tv_focusshop)
    TextView tv_focusshop;//关注店铺
    @BindView(R.id.appbar_layout)
    AppBarLayout appbar_layout;//
    @BindView(R.id.view_titlebg)
    View view_titlebg;//
    @BindView(R.id.iv_shop_backblack)
    ImageView iv_shop_backblack;//灰色返回按钮
    @BindView(R.id.tv_focusshopblack)
    TextView tv_focusshopblack;//灰色关注按钮
    @BindView(R.id.iv_shop_shareblack)
    ImageView iv_shop_shareblack;//灰色分享按钮
    @BindView(R.id.rl_shop_searchblack)
    RelativeLayout rl_shop_searchblack;//灰色搜索布局

    Toolbar tool_bar, tool_barblack;//

    @BindView(R.id.img_my)
    CornerImageView img_my;//店铺第一条评论头像
    @BindView(R.id.tv_mynickname)
    TextView tv_mynickname;//店铺第一条评论昵称
    @BindView(R.id.star01)
    ImageView star01;//店铺第一条评论星
    @BindView(R.id.star02)
    ImageView star02;//店铺第一条评论星
    @BindView(R.id.star03)
    ImageView star03;//店铺第一条评论星
    @BindView(R.id.star04)
    ImageView star04;//店铺第一条评论星
    @BindView(R.id.star05)
    ImageView star05;//店铺第一条评论星
    @BindView(R.id.tv_time)
    TextView tv_time;//店铺第一条评论时间
    @BindView(R.id.tv_remakecontent)
    TextView tv_remakecontent;//店铺第一条评论内容
    @BindView(R.id.recycler_img)
    RecyclerView recycler_img;//店铺第一条评论图片
    @BindView(R.id.tv_goodszan)
    RadioButton tv_goodszan;//店铺第一条评论赞
    @BindView(R.id.rl_remake)
    RelativeLayout rl_remake;//店铺第一条评论布局
    @BindView(R.id.ll_all_evaluation)
    LinearLayout ll_all_evaluation;//全部评论
    @BindView(R.id.tv_allstar)
    TextView tv_allstar;//店铺评论星
    @BindView(R.id.tv_remakecount)
    TextView tv_remakecount;//店铺评论条数

    private ShopCarPopupWindow shard_PW;//分享弹窗
    private ArrayList<String> oneList = new ArrayList<>();//一级标题头
    private ArrayList<Integer> one_list_positon = new ArrayList<>();//每个一级头开始的下标
    //    private ArrayList<GoodsBeen> two_list = new ArrayList<>();
    private ArrayList<ShopGoodListBeen.DataBean.GoodsInfoBean> goodList = new ArrayList<>();//右边商品的列表
    //购物车里adpter
    private ArrayList<ShopCarListBeen.DataBean.ValidBean.GoodsBeanX> carList = new ArrayList();
    private ShopRetailLeftLVAdapter shopRetailLeftLVAdapter;
    private ShopRetailRightAdapter shopRetailRightAdapter;
    private ShopCarGoodsAdapter shopCarGoodsAdapter;
    private String menu_name;// 菜单名
    private LinearLayoutManager linearManager;
    private int total_num = 0;
    private String total_price = "0";
    private int height;
    private ShopCarPopupWindow carPopupWindow;
    private boolean is_from_car = false;
    private Dialog dialog;
    private int is_new = 0;//是否是直接购买
    private String shopID = "";//店铺id
    private String goodID = "";//商品id
    private RelativeLayout.LayoutParams item_bar;
    private String offline_shop_name;//线下店铺名
    private String logo;//线下店铺logo
    private String intro;//店铺经营信息
    private Context mContext;
    private boolean isFocusShop = false;
    private Bitmap bitmap;
    private int remakeCount;
    private String comprehensive;
    private ShopRemakeListRetailBean.DataBean.ReplyBean replyBean;
    private OrderMyRemake_RetailImageListAdapter imageListAdapter;
    @Override
    public int getLayoutId() {
        return R.layout.activity_shop;
    }

    @Override
    public void initView() {
        //获取组件高度
//        initOnPreDrawListener();
        mContext = ShopActivity.this;
        mPresenter = new ShopRetailPresenter();
        mPresenter.attachView(this);
        initHigh();
        StatusBarUtil.setLightStatusBar(this, false, true);
        deafult_view();
        shopID = getIntent().getStringExtra("shop_id");
        goodID = getIntent().getStringExtra("good_id");
        tool_bar = findViewById(R.id.tool_bar);
        tool_barblack = findViewById(R.id.tool_barblack);
        shopRetailLeftLVAdapter = new ShopRetailLeftLVAdapter(this);
        lvMenuLeft.setAdapter(shopRetailLeftLVAdapter);

        lvMenuLeft.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                shopRetailLeftLVAdapter.setSelectItem(i);
                shopRetailLeftLVAdapter.notifyDataSetChanged();
                rvShopGoods.scrollToPosition(one_list_positon.get(i));
                //第一
                linearManager.scrollToPositionWithOffset(one_list_positon.get(i), 0);
//                tvTitleRight.setText(two_list.get(one_list_positon.get(i)).title_name);
            }
        });

        rvShopGoods.addOnScrollListener(new RecyclerView.OnScrollListener() {
            private int scrollState;

            @Override
            public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
                super.onScrollStateChanged(recyclerView, newState);
                this.scrollState = newState;
            }

            @Override
            public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
                super.onScrolled(recyclerView, dx, dy);
                if (scrollState == AbsListView.OnScrollListener.SCROLL_STATE_IDLE) {
                    return;
                }
                //获取最后一个可见view的位置
                int lastItemPosition = linearManager.findLastVisibleItemPosition();
                //获取第一个可见view的位置
                int firstItemPosition = linearManager.findFirstVisibleItemPosition();

                if (!goodList.get(firstItemPosition).getCategory_name().equals(menu_name)) {
                    menu_name = goodList.get(firstItemPosition).getCategory_name();
                    int index = oneList.indexOf(menu_name);
                    shopRetailLeftLVAdapter.setSelectItem(index);
                    shopRetailLeftLVAdapter.notifyDataSetInvalidated();
                    tvTitleRight.setText(goodList.get(firstItemPosition).getCategory_name());
                }

            }
        });
        rvShopGoods.setLayoutManager(new LinearLayoutManager(this));
        rvShopGoods.setItemAnimator(new DefaultItemAnimator());
        shopRetailRightAdapter = new ShopRetailRightAdapter(this, goodList, this,shopID);
        shopRetailRightAdapter.setOnItemClickListener(new ItemClickListener() {
            @Override
            public void onItemClick(int position) {
                Intent intent = new Intent(ShopActivity.this, GoodsDetailsActivity.class);
                intent.putExtra("good_id", goodList.get(position).getId() + "");

                startActivity(intent);
            }
        });
        rvShopGoods.setAdapter(shopRetailRightAdapter);


        linearManager = (LinearLayoutManager) rvShopGoods.getLayoutManager();


        maxHeightRv.setLayoutManager(new LinearLayoutManager(this));
        maxHeightRv.setItemAnimator(new DefaultItemAnimator());
        shopCarGoodsAdapter = new ShopCarGoodsAdapter(this, carList, mPresenter);
        maxHeightRv.setAdapter(shopCarGoodsAdapter);

        //网络请求
        mPresenter.shopStoreInfo(shopID, "0");
        mPresenter.shopRetail(shopID);
        Map<String,Object> map = new HashMap<>();
        map.put("storeId",shopID);
        map.put("limit",1);
        map.put("page",1);
        map.put("search",1);
        map.put("content",2);
        mPresenter.getShopRemakeRetail(map);

        initTitleScrowMode();
        StatusBarUtil.transparencyBar(this);
    }

    private void initHigh() {
        item_bar = (RelativeLayout.LayoutParams) llState.getLayoutParams();
        item_bar.height = StatusBarUtil.getStatusBarHeight(this);
        llState.setLayoutParams(item_bar);

        item_bar = (RelativeLayout.LayoutParams) ll_stateblack.getLayoutParams();
        item_bar.height = StatusBarUtil.getStatusBarHeight(this);
        ll_stateblack.setLayoutParams(item_bar);

    }

    /**
     * 设置头部滚动渐变效果
     */
    private void initTitleScrowMode() {
        appbar_layout.addOnOffsetChangedListener(new AppBarLayout.OnOffsetChangedListener() {
            @Override
            public void onOffsetChanged(AppBarLayout appBarLayout, int verticalOffset) {
                tool_bar.setBackgroundColor(changeAlpha(getResources().getColor(R.color.color_FFFFFF), Math.abs(verticalOffset * 1.0f) / appBarLayout.getTotalScrollRange()));
                //  viewTitleBg.setBackgroundColor(changeAlpha(getResources().getColor(R.color.color_FFFFFF),Math.abs(verticalOffset*1.0f)/appBarLayout.getTotalScrollRange()));
                // viewTitleBg.setBackgroundColor(changeAlpha(getResources().getColor(R.color.color_FFFFFF),Math.abs(verticalOffset*1.0f)/appBarLayout.getTotalScrollRange()));
                // llState.setBackgroundColor(changeAlpha(getResources().getColor(R.color.color_FFFFFF),Math.abs(verticalOffset*1.0f)/appBarLayout.getTotalScrollRange()));
                Log.e("verticalOffset", verticalOffset + "-----");
                if (verticalOffset >= -300) {
                    tool_barblack.setVisibility(View.GONE);
                    StatusBarUtil.transparencyBar(ShopActivity.this);
                    //setDarkTitleSysBg();
                } else {
                    tool_barblack.setVisibility(View.VISIBLE);

                    setLightTitleSysBg();
                }

//                if (verticalOffset>= -500){
//                    setDarkTitleSysBg();
//                }else {
//                    setLightTitleSysBg();
//                }


            }
        });
    }

    private void deafult_view() {
        tvTotalGoodsNum.setText(total_num + "");
        tvTotalGoodsNum.setVisibility(View.INVISIBLE);

        if (total_num == 0) {
            viewShopCarBg.setBackgroundResource(R.drawable.round_hui_bg);
            tvToSettleAccounts.setBackgroundResource(R.color.color_999999);
            tvShopCarPrice.setText(getResources().getText(R.string.unselected_goods));
            tvShopCarPrice.setTextSize(14);
            tvShopCarPrice.setTextColor(getResources().getColor(R.color.color_999999));
            tvTotalGoodsNum.setVisibility(View.INVISIBLE);
        }
    }


    @Override
    public void showLoading() {
        if (!ProgressDialog.getInstance().materialDialog.isShowing()) {
            ProgressDialog.getInstance().show(this);
        }
    }

    @Override
    public void hideLoading() {

        ProgressDialog.getInstance().dismiss();

    }

    @Override
    public void onError(Throwable throwable) {
        Toast.makeText(this, "网络请求出错", Toast.LENGTH_SHORT).show();
    }

    @Override
    protected void onStop() {
        super.onStop();
        if (null != sonicView) {
            sonicView.stop();
        }
    }

    @Override
    public void onShopRetailSuccess(ShopGoodListBeen bean) {
        if (bean.getStatus() == Constants.SUCCESS_CODE) {
            oneList.clear();
            goodList.clear();
            one_list_positon.clear();
            int index = 0;
            for (ShopGoodListBeen.DataBean dataBean : bean.getData()) {
                if (dataBean.getGoods_info().size() != 0) {
                    oneList.add(dataBean.getCategorey_name());
                    goodList.addAll(dataBean.getGoods_info());
                    if (carList.size() != 0) {
                        for (ShopCarListBeen.DataBean.ValidBean.GoodsBeanX goodsBeanX : carList) {
                            for (int k = 0; k < goodList.size(); k++) {
                                if (goodList.get(k).getId() == goodsBeanX.getProduct_id()) {
                                    goodList.get(k).setGood_sum(goodsBeanX.getCart_num());

                                    break;
                                }
                            }
                        }
                        calculate();
                        shopRetailRightAdapter.notifyDataSetChanged();
                    }
                    one_list_positon.add(index);
                    goodList.get(index).setIs_title(true);
                    index += dataBean.getGoods_info().size();
                }
            }
            if (oneList.size() != 0) {
                menu_name = oneList.get(0);
            }
            shopRetailLeftLVAdapter.setData(oneList);
            shopRetailRightAdapter.notifyDataSetChanged();
            if (null != goodID) {
                //不为空  商品自动滚动第一
                for (int good_position = 0; good_position < goodList.size(); good_position++) {
                    if (goodID.equals(goodList.get(good_position).getId() + "")) {
                        rvShopGoods.scrollToPosition(good_position);
                        //第一
                        linearManager.scrollToPositionWithOffset(good_position, 0);
                    }
                }
            }
        } else {
            Toast.makeText(this, bean.getMsg(), Toast.LENGTH_SHORT).show();
        }
    }

    private String store_qualifications_img;

    @Override
    public void onShopStoreInfoSuccess(StoreInfoBeen bean) {
        if (bean.getStatus() == Constants.SUCCESS_CODE) {
            if (bean.getData().getIs_self_extracting() == 0) {
                tvShopCarHint.setVisibility(View.GONE);
            }
            //直播中的显示
            if (bean.getData().getLive_id() == 0) {
                rlVideoZhibo.setVisibility(View.GONE);
            } else {
                rlVideoZhibo.setVisibility(View.VISIBLE);
                rlVideoZhibo.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        Intent intent = new Intent(mContext, VideoActivity.class);
                        intent.putExtra("live_id", bean.getData().getLive_id() + "");
                        intent.putExtra("shop_type", "0");
                        startActivity(intent);
                    }
                });
            }
            if (bean.getData().getBusiness_hours() == null) {
                tvBusinessHoursTime.setText("全天");
            } else {
                tvBusinessHoursTime.setText(bean.getData().getBusiness_hours());
            }
            store_qualifications_img = bean.getData().getStore_qualifications_img();
            tvMonthSales.setText(bean.getData().getMonthly_sales() + "");
            tvInfo.setText(bean.getData().getIntro() + "");
            if (bean.getData().getStore_banner().size() != 0) {
                rlActivity.setVisibility(View.VISIBLE);
                if (bean.getData().getStore_banner().size() == 1) {

                    rvActivity.setVisibility(View.GONE);
                    RoundedCorners roundedCorners = new RoundedCorners(1);
                    //通过RequestOptions扩展功能,override:采样率,因为ImageView就这么大,可以压缩图片,降低内存消耗
                    RequestOptions options = RequestOptions.bitmapTransform(roundedCorners);
                    options.placeholder(R.drawable.icon_defult)//图片加载出来前，显示的图片
                            .fallback(R.drawable.icon_defult) //url为空的时候,显示的图片
                            .error(R.drawable.icon_defult);
                    Glide.with(this).load(bean.getData().getStore_banner().get(0)).apply(options.transform(new CenterCrop(), roundedCorners)).into(ivActivity);
                } else {
                    ivActivity.setVisibility(View.GONE);
                    LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this);
                    linearLayoutManager.setOrientation(LinearLayoutManager.HORIZONTAL);
                    ItemOffsetDecoration itemDecoration = new ItemOffsetDecoration(this, R.dimen.item_offset);
                    rvActivity.setLayoutManager(linearLayoutManager);
                    rvActivity.addItemDecoration(itemDecoration);
                    ShopActivityAdapter shopActivityAdapter = new ShopActivityAdapter(this, bean.getData().getStore_banner());

                    rvActivity.setAdapter(shopActivityAdapter);
                }
            } else {
                rlActivity.setVisibility(View.GONE);
            }


            //顶部左边圆角
            RoundedFormation transformationlefttop = new RoundedFormation
                    (60, 0, RoundedFormation.CornerType.TOP_LEFT);
            RoundedFormation transformation1leftbottom = new RoundedFormation
                    (12, 0, RoundedFormation.CornerType.BOTTOM_LEFT);
            RoundedFormation transformationrighttop = new RoundedFormation
                    (12, 0, RoundedFormation.CornerType.TOP_RIGHT);
            RoundedFormation transformation1rightbottom = new RoundedFormation
                    (12, 0, RoundedFormation.CornerType.BOTTOM_RIGHT);

            // RoundedCorners roundedCorners = new RoundedCorners(2);
            //组合各种Transformation,
            MultiTransformation<Bitmap> mation = new MultiTransformation<>
                    //Glide设置圆角图片后设置ImageVIew的scanType="centerCrop"无效解决办法,将new CenterCrop()添加至此
                    (new CenterCrop(), transformationlefttop, transformation1leftbottom, transformationrighttop, transformation1rightbottom);

            //通过RequestOptions扩展功能,override:采样率,因为ImageView就这么大,可以压缩图片,降低内存消耗
            RequestOptions options = RequestOptions.bitmapTransform(mation).override(200, 200);
            options.placeholder(R.drawable.icon_defult)//图片加载出来前，显示的图片
                    .fallback(R.drawable.icon_defult) //url为空的时候,显示的图片
                    .error(R.drawable.icon_defult);
            Glide.with(this).load(bean.getData().getLogo()).apply(options.transform(mation)).into(ivShopHead);
            Glide.with(this).asBitmap().load(bean.getData().getLogo()).into(new SimpleTarget<Bitmap>() {
                @Override
                public void onResourceReady(@NonNull Bitmap resource, @Nullable Transition<? super Bitmap> transition) {

                    //viewTitleBg.setBackground(new BitmapDrawable(getResources(), Utils.fastblur(resource,200)));
                    PaletteHelper.setPaletteColor(resource, viewTitleBg);
                    PaletteHelper.setPaletteColor(resource, view_titlebg);

                }
            });


//            Glide.with(this).load(bean.getData().getLogo()).listener(new RequestListener<Drawable>() {
//                @Override
//                public boolean onLoadFailed(@Nullable GlideException e, Object model, Target<Drawable> target, boolean isFirstResource) {
//                    //失败加载的默认图片
////                    viewShopBg.setBackground(getResources().getDrawable(R.drawable.image_shop_xfd));
//                    return false;
//                }
//
//                @Override
//                public boolean onResourceReady(Drawable resource, Object model, Target<Drawable> target, DataSource dataSource, boolean isFirstResource) {
//                    //成功加载的图片
//                    viewTitleBg.post(() -> {
//                        viewTitleBg.setBackground(resource);
//
//                    });
//                    return true;
//                }
//            }).into(viewTitleBg.getWidth(), viewTitleBg.getHeight());
            tvShopName.setText(bean.getData().getOffline_shop_name());
            tvIntroduce.setText("顺丰配送|基础运费" + bean.getData().getBase_freight() + "元");
            if (bean.getData().getIs_close() == 0) {
                tvDayang.setVisibility(View.GONE);
            } else {
                tvDayang.setVisibility(View.VISIBLE);
            }
            tvAddress.setText(bean.getData().getAddress());
            tvShopPhone.setText(bean.getData().getMobile());
            offline_shop_name = bean.getData().getOffline_shop_name();
            logo = bean.getData().getLogo();
            Log.e("getLogo", logo + "----");
            intro = bean.getData().getIntro();
            isFocusShop = bean.getData().isIs_collect();
            if (isFocusShop) {
                tv_focusshop.setText("已关注");
                tv_focusshopblack.setText("已关注");
            } else {
                tv_focusshop.setText("关注");
                tv_focusshopblack.setText("关注");
            }
        } else {
            Toast.makeText(this, bean.getMsg(), Toast.LENGTH_SHORT).show();
        }
    }

    @Override
    public void onAddCarSuccess(ConfirmGoodBeen bean) {
        if (bean.getStatus() == Constants.SUCCESS_CODE) {
            mPresenter.shopCarList(shopID, "0");
        } else {
            if (bean.getStatus() == Constants.LOGIN_CODE) {
                UtilsData.getPreference(this, "login").remove("head_url");
                UtilsData.getPreference(this, "login").remove("nickname");
                UtilsData.getPreference(this, "login").remove("is_store");
                UtilsData.getPreference(this, "login").remove("token");
                APP_TOKEN = "";
                Intent intent = new Intent(this, OneLoginMainActivity.class);
                startActivity(intent);
                return;
            }
            Toast.makeText(this, bean.getMsg(), Toast.LENGTH_SHORT).show();
        }

    }

    @Override
    public void onShopCarListSuccess(ShopCarListBeen bean) {
        if (bean.getStatus() == Constants.SUCCESS_CODE) {
            for (int k = 0; k < goodList.size(); k++) {
                goodList.get(k).setGood_sum(0);
            }
            carList.clear();
            if (bean.getData().getValid().size() != 0) {
                carList.addAll(bean.getData().getValid().get(0).getGoods());
                for (ShopCarListBeen.DataBean.ValidBean.GoodsBeanX goodsBeanX : carList) {
                    for (int k = 0; k < goodList.size(); k++) {
                        if (goodList.get(k).getId() == goodsBeanX.getProduct_id()) {
                            goodList.get(k).setGood_sum(goodsBeanX.getCart_num());
                            break;
                        }
                    }
                }
            }
            calculate();
            shopRetailRightAdapter.notifyDataSetChanged();
            shopCarGoodsAdapter.notifyDataSetChanged();
        } else {
//            Toast.makeText(this, bean.getMsg(), Toast.LENGTH_SHORT).show();
        }
    }

    @Override
    public void onUpdateCarNumSuccess(BaseObjectBean bean, int number, int one_position, int position) {
        if (bean.getStatus() == Constants.SUCCESS_CODE) {
            for (ShopGoodListBeen.DataBean.GoodsInfoBean goodsInfoBean : goodList) {
                if (goodsInfoBean.getId() == carList.get(position).getProduct_id()) {
                    goodsInfoBean.setGood_sum(number);
                }
            }
            carList.get(position).setCart_num(number);
            calculate();
            shopCarGoodsAdapter.notifyDataSetChanged();
            shopRetailRightAdapter.notifyDataSetChanged();
        } else {
            if (bean.getStatus() == Constants.LOGIN_CODE) {
                UtilsData.getPreference(this, "login").remove("head_url");
                UtilsData.getPreference(this, "login").remove("nickname");
                UtilsData.getPreference(this, "login").remove("is_store");
                UtilsData.getPreference(this, "login").remove("token");
                APP_TOKEN = "";
                Intent intent = new Intent(this, OneLoginMainActivity.class);
                startActivity(intent);
                return;
            }
            Toast.makeText(this, bean.getMsg(), Toast.LENGTH_SHORT).show();
        }
    }

    /**
     * 使用BigDecimal，保留小数点后两位
     */
    public String format1(double value) {

        BigDecimal bd = new BigDecimal(value);
        bd = bd.setScale(2, RoundingMode.HALF_UP);
        return bd.toString();
    }

    @Override
    public void onRemoveGoodSuccess(BaseObjectBean bean, String goodID, int position, boolean isAll) {
        if (bean.getStatus() == Constants.SUCCESS_CODE) {
            if (isAll) {
                mPresenter.shopCarList(shopID, "0");
            } else {
                for (ShopGoodListBeen.DataBean.GoodsInfoBean goodsInfoBean : goodList) {
                    if (goodsInfoBean.getId() == carList.get(position).getProduct_id()) {
                        goodsInfoBean.setGood_sum(0);
                    }
                }
                carList.remove(position);
                calculate();
                shopCarGoodsAdapter.notifyDataSetChanged();
                shopRetailRightAdapter.notifyDataSetChanged();
            }
        } else {
            if (bean.getStatus() == Constants.LOGIN_CODE) {
                UtilsData.getPreference(this, "login").remove("head_url");
                UtilsData.getPreference(this, "login").remove("nickname");
                UtilsData.getPreference(this, "login").remove("is_store");
                UtilsData.getPreference(this, "login").remove("token");
                APP_TOKEN = "";
                Intent intent = new Intent(this, OneLoginMainActivity.class);
                startActivity(intent);
                return;
            }
            Toast.makeText(this, bean.getMsg(), Toast.LENGTH_SHORT).show();
        }
    }

    @Override
    public void onInitDataSuccess(XFDGoodsDetailsBeen bean) {
        //这里用不到
    }

    @Override
    public void onConfirmSuccess(ConfirmGoodBeen bean) {
        if (bean.getStatus() == Constants.SUCCESS_CODE) {
            Intent confirmOrder = new Intent(this, ConfirmOrderActivity.class);
            confirmOrder.putExtra("confirm", bean.getData());
            startActivity(confirmOrder);
        } else if (bean.getStatus() == 2000) {
            Toast.makeText(this, "此商铺已打烊", Toast.LENGTH_SHORT).show();
        } else {
            if (bean.getStatus() == Constants.LOGIN_CODE) {
                UtilsData.getPreference(this, "login").remove("head_url");
                UtilsData.getPreference(this, "login").remove("nickname");
                UtilsData.getPreference(this, "login").remove("is_store");
                UtilsData.getPreference(this, "login").remove("token");
                APP_TOKEN = "";
                Intent intent = new Intent(this, OneLoginMainActivity.class);
                startActivity(intent);
                return;
            }
            Toast.makeText(this, bean.getMsg(), Toast.LENGTH_SHORT).show();
        }
    }

    @Override
    public void getStoreGoodsListSuccess(MoreGoodsBean bean) {
        //这里用不到
    }

    @Override
    public void getGoodsCollectionSuccess(MoreGoodsBean bean) {

    }

    @Override
    public void getGoodsCancleCollectionSuccess(MoreGoodsBean bean) {

    }

    @Override
    public void getFocusShopSuccess(StoreInfoBeen bean) {
        if (bean.getStatus() == Constants.SUCCESS_CODE) {
            isFocusShop = !isFocusShop;
            if (isFocusShop) {
                tv_focusshop.setText("已关注");
                tv_focusshopblack.setText("已关注");
            } else {
                tv_focusshop.setText("关注");
                tv_focusshopblack.setText("关注");
            }
        } else {
            ToastUtils.s(this, bean.getMsg());
        }
    }

    /**请求店铺评价列表成功*/
    @Override
    public void onGetShopRemakeRetailSuccess(ShopRemakeListRetailBean bean) {
        if (bean.getStatus() == Constants.SUCCESS_CODE) {
            remakeCount = bean.getData().getCount();
            comprehensive = bean.getData().getComprehensive();
            tv_allstar.setText(comprehensive);
            tv_remakecount.setText(remakeCount+"");
            if (EmptyUtil.isNotEmpty(bean.getData().getReply())){
                rl_remake.setVisibility(View.VISIBLE);
                replyBean = bean.getData().getReply().get(0);

                img_my.setType(CornerImageView.TYPE_CIRCLE);
                ImageGlideUtil.loadImage(this,img_my,replyBean.getUser().getAvatar());
                tv_mynickname.setText(replyBean.getUser().getNickname()==null?"":replyBean.getUser().getNickname());
                tv_time.setText(replyBean.getReplay().getCreated_at());
                if (EmptyUtil.isNotEmpty(replyBean.getReplay().getComment())){
                    tv_remakecontent.setVisibility(View.VISIBLE);
                    tv_remakecontent.setText(replyBean.getReplay().getComment());
                }else {
                    tv_remakecontent.setVisibility(View.GONE);
                }
                recycler_img.setLayoutManager(new GridLayoutManager(mContext,3));
                if (EmptyUtil.isNotEmpty(replyBean.getReplay().getPics())){
                    imageListAdapter = new OrderMyRemake_RetailImageListAdapter(replyBean.getReplay().getPics());
                    recycler_img.setAdapter(imageListAdapter);
                }

                String zanGoods = " ";
                if (EmptyUtil.isNotEmpty(replyBean.getGoods())){
                    tv_goodszan.setVisibility(View.VISIBLE);
                    for (int i = 0; i < replyBean.getGoods().size(); i++) {
                        if (replyBean.getGoods().get(i).getIs_fabulous()==1){
                            zanGoods = zanGoods+replyBean.getGoods().get(i).getGoods_name()+"，";
                        }
                    }
                    tv_goodszan.setText(zanGoods.substring(0,zanGoods.length()-1));
                }else {
                    tv_goodszan.setVisibility(View.GONE);
                }

                clearState(star01,star02,star03,star04,star05,replyBean.getReplay().getService_score());
                if (remakeCount==0){
                    ll_all_evaluation.setVisibility(View.GONE);
                }
            }else {
                ll_all_evaluation.setVisibility(View.GONE);
                rl_remake.setVisibility(View.GONE);
            }

        } else {
            ToastUtils.s(this, bean.getMsg());
        }
    }

    @OnClick({R.id.tv_clear_all, R.id.tv_to_settle_accounts, R.id.iv_shop_back, R.id.ll_all_evaluation,
            R.id.tv_onclick_look, R.id.tv_shop_phone, R.id.ll_led_securities, R.id.rl_shop_search,
            R.id.ll_onclick_pack_up, R.id.view_shop_info_1, R.id.view_shop_info_2, R.id.rl_shop_car,
            R.id.view_bg_black, R.id.ll_car, R.id.iv_shop_share, R.id.tv_focusshop, R.id.rl_shop_searchblack,
            R.id.iv_shop_shareblack, R.id.tv_focusshopblack, R.id.iv_shop_backblack})

    public void onclick(View view) {
        switch (view.getId()) {
            case R.id.tv_clear_all:
                if (Utils.isFastClick()) {
                    dialog = Utils.addDialog(this, R.layout.dialog, R.string.are_you_sure_you_want_to_clear_this_car, R.string.confirm, new View.OnClickListener() {
                        @Override
                        public void onClick(View view) {
                            if (Utils.isFastClick()) {
                                String ids = "";
                                for (ShopCarListBeen.DataBean.ValidBean.GoodsBeanX goodsBeanX : carList) {
                                    if (ids.isEmpty()) {
                                        ids = goodsBeanX.getId() + "";
                                    } else {
                                        ids = ids + "," + goodsBeanX.getId();
                                    }
                                }
                                mPresenter.removeGood(ids + "", "" + "", 0, true);
                                dialog.dismiss();
                            }
                        }
                    });
                    dialog.show();
                }
                break;
            case R.id.tv_to_settle_accounts:
                if (Utils.isFastClick()) {
                    if (EmptyUtil.isEmpty(APP_TOKEN)) {
                        Intent intent = new Intent(this, OneLoginMainActivity.class);
                        startActivity(intent);
                        return;
                    }
                    if (carList.size() != 0) {
                        String ids = "";
                        for (ShopCarListBeen.DataBean.ValidBean.GoodsBeanX goodsBeanX : carList) {
                            if (ids.isEmpty()) {
                                ids = goodsBeanX.getId() + "";
                            } else {
                                ids = ids + "," + goodsBeanX.getId();
                            }
                        }
                        String user_curent_lng = UtilsData.getPreference(this, "coordinates").getString("coordinates_lng");
                        String user_curent_lat = UtilsData.getPreference(this, "coordinates").getString("coordinates_lat");
                        mPresenter.confirm(ids, user_curent_lng, user_curent_lat);
                    } else {
                        Toast.makeText(this, "请选择商品", Toast.LENGTH_SHORT).show();
                    }
                }
                break;
            case R.id.iv_shop_back:
            case R.id.iv_shop_backblack:
                finish();
                break;
            case R.id.ll_all_evaluation:
                if (Utils.isFastClick()) {
                    //Intent evaluation = new Intent(this, AllCommentsActivity.class);
                    Intent evaluation = new Intent(this, ShopRemake_RetailActivity.class);
                    evaluation.putExtra("storeId",shopID);
                    startActivity(evaluation);
                }
                break;
            case R.id.tv_onclick_look:
                if (Utils.isFastClick()) {
                    Intent business = new Intent(this, MerchantsQualificationActivity.class);
                    business.putExtra("image", store_qualifications_img);
                    startActivity(business);
                }
                break;
            case R.id.tv_shop_phone:
                if (Utils.isFastClick()) {
                    dialog = Utils.addDialog(this, R.layout.dialog, tvShopPhone.getText().toString(), R.string.call, new View.OnClickListener() {
                        @Override
                        public void onClick(View view) {
                            if (Utils.isFastClick()) {
                                dialog.dismiss();
                                Intent intent = new Intent(Intent.ACTION_DIAL);
                                Uri data = Uri.parse("tel:" + tvShopPhone.getText());
                                intent.setData(data);
                                startActivity(intent);
                            }

                        }
                    });
                    dialog.show();
                }
                break;
            case R.id.ll_led_securities:
                if (Utils.isFastClick()) {
                    if (carPopupWindow != null) {

                    } else {
                        carPopupWindow = new ShopCarPopupWindow(this, R.layout.pw_shop_coupon);
                        carPopupWindow.getRootView().findViewById(R.id.iv_back).setOnClickListener(new View.OnClickListener() {
                            @Override
                            public void onClick(View view) {
                                if (Utils.isFastClick()) {
                                    carPopupWindow.shareClose();
                                    if (is_from_car) {
                                        if (llCar.getVisibility() == View.GONE) {
                                            startTranslationAnimation();
                                            is_from_car = false;
                                        }
                                    }
                                }
                            }
                        });
                        ((ListView) carPopupWindow.getRootView().findViewById(R.id.lv_man_jian)).setAdapter(new CarManJianLVAdapter(this, new ArrayList<CarManJianBeen>()));
                        ((ListView) carPopupWindow.getRootView().findViewById(R.id.lv_juan)).setAdapter(new CarCouponsLVAdapter(this, new ArrayList<CarCouponsBeen>()));
                    }
                    if (llCar.getVisibility() != View.GONE) {
//                    关闭平移动画
                        endTranslationAnimation();
                        is_from_car = true;
                    }
                    carPopupWindow.showPopupWindow();
                }
                break;
            case R.id.rl_shop_search:
            case R.id.rl_shop_searchblack:
                if (Utils.isFastClick()) {
                    Intent intent = new Intent(this, ShopSearchGoodsActivity.class);
                    intent.putExtra("shop_id", shopID);
                    startActivity(intent);
                }
                break;
            case R.id.ll_onclick_pack_up:
                if (Utils.isFastClick()) {
                    isDetail = false;
                    svOnclickPackUp.setVisibility(View.INVISIBLE);
                    llOnclickPackUp.setVisibility(View.INVISIBLE);
                    rlShopBottom.setVisibility(View.VISIBLE);
                }
                break;
            case R.id.view_shop_info_1:
            case R.id.view_shop_info_2:
                if (Utils.isFastClick()) {
                    if (isDetail) {
                        isDetail = false;
                        svOnclickPackUp.setVisibility(View.INVISIBLE);
                        llOnclickPackUp.setVisibility(View.INVISIBLE);
                        rlShopBottom.setVisibility(View.VISIBLE);
                    } else {
                        isDetail = true;
                        svOnclickPackUp.setVisibility(View.VISIBLE);
                        llOnclickPackUp.setVisibility(View.VISIBLE);
                        rlShopBottom.setVisibility(View.INVISIBLE);
                    }
                }
                break;
            case R.id.rl_shop_car:
                if (Utils.isFastClick()) {
                    if (total_num == 0) {
                        return;
                    }
                    if (llCar.getVisibility() == View.GONE) {
                        startTranslationAnimation();
                    } else {
//                    关闭平移动画
                        endTranslationAnimation();
                    }
                }
                break;
            case R.id.view_bg_black:
                if (Utils.isFastClick()) {
                    // 关闭平移动画
                    endTranslationAnimation();
                }
                break;
            case R.id.ll_car:

                break;
            case R.id.iv_shop_share://分享店铺
            case R.id.iv_shop_shareblack://分享店铺
                if (Utils.isFastClick()) {
                    //解決微信登录和友盟分享sdk回调冲突问题,调用友盟分享时候需要重新设置微信参数
                    PlatformConfig.setWeixin(Constants.WX_APPID, Constants.WX_SECRET);
                    if (shard_PW == null) {
                        shard_PW = new ShopCarPopupWindow(this, R.layout.pw_shard);
                        shard_PW.getRootView().findViewById(R.id.tv_cancel).setOnClickListener(new View.OnClickListener() {
                            @Override
                            public void onClick(View view) {
                                shard_PW.shareClose();
                            }
                        });
                        /**点击分享微信*/
                        shard_PW.getRootView().findViewById(R.id.ll_wechat_firend).setOnClickListener(new View.OnClickListener() {
                            @Override
                            public void onClick(View view) {
                                if (Utils.isFastClick()) {
                                    //Log.e("shareToXcc","shareToXcc");
                                    if (EmptyUtil.isEmpty(offline_shop_name)) {
                                        offline_shop_name = "线下实体店铺";
                                    }
                                    shareToXcc(logo, offline_shop_name
                                            , intro, shopID);
                                }
                            }
                        });

                        /**点击分享朋友圈*/
                        shard_PW.getRootView().findViewById(R.id.ll_wechat_pyq).setOnClickListener(new View.OnClickListener() {
                            @Override
                            public void onClick(View view) {
                                ToastUtils.s(ShopActivity.this, "商品和店铺分享小程序目前只支持微信好友分享哦");
                            }
                        });


                    }
                    shard_PW.showPopupWindow();
                }
                break;
            case R.id.tv_focusshop://关注
            case R.id.tv_focusshopblack://关注
                if (EmptyUtil.isNotEmpty(APP_TOKEN)) {
                    if (Utils.isFastClick()) {
                        mPresenter.getFocusShop(shopID);
                    }
                } else {
                    Intent intent = new Intent(this, OneLoginMainActivity.class);
                    startActivity(intent);
                }
                break;

        }
    }

    boolean isDetail = false;

    @Override
    public void onBackPressed() {
        if (llCar.getVisibility() != View.GONE) {
//                    关闭平移动画
            endTranslationAnimation();
            return;
        }
        if (null != dialog) {
            if (dialog.isShowing()) {
                dialog.dismiss();
                return;
            }

        }
        if (null != carPopupWindow) {
            if (carPopupWindow.isShowing()) {
                carPopupWindow.shareClose();
                return;
            }
        }
        super.onBackPressed();
    }

    @Override
    public void addAction(View view, int position, boolean is) {

        ShoppingCartAnimationView shoppingCartAnimationView = new ShoppingCartAnimationView(this);
        int postion[] = new int[2];
        view.getLocationInWindow(postion);
        shoppingCartAnimationView.setStartPosition(new Point(postion[0], postion[1]));
        ViewGroup rootView = (ViewGroup) getWindow().getDecorView();
        rootView.addView(shoppingCartAnimationView);
        int endPosition[] = new int[2];
        ivShopCar.getLocationInWindow(endPosition);
        shoppingCartAnimationView.setEndPosition(new Point(endPosition[0], endPosition[1]));
        shoppingCartAnimationView.startBeizerAnimation();
        rlShopCar.setAnimation(shakeAnimation(1));

        calculate();//本地总数

//修改商品
        if (goodList.get(position).getGood_sum() == 0) {
            mPresenter.addCar(is_new + "", "", goodList.get(position).getId() + "", "1");
        } else {
            for (int k = 0; k < carList.size(); k++) {
                if (goodList.get(position).getId() == carList.get(k).getProduct_id()) {
                    mPresenter.updateCarNum(carList.get(k).getId() + "", goodList.get(position).getGood_sum() + 1, 0, k);//one_position无用
                    break;
                }
            }
        }
    }

    @Override
    public void minusGood(int position, boolean is) {
        calculate();//本地总数
        for (int k = 0; k < carList.size(); k++) {
            if (goodList.get(position).getId() == carList.get(k).getProduct_id()) {
                if (goodList.get(position).getGood_sum() == 1) {
                    //移除商品
                    mPresenter.removeGood(carList.get(k).getId() + "", carList.get(k).getId() + "", k, false);
                } else {
                    mPresenter.updateCarNum(carList.get(k).getId() + "", goodList.get(position).getGood_sum() - 1, 0, k);//one_position无用
                }
                break;
            }
        }


    }

    /**
     * 计算
     */
    public void calculate() {
        int num = 0;
        double price = 0;
        for (ShopGoodListBeen.DataBean.GoodsInfoBean goodsInfoBean : goodList) {
            num += goodsInfoBean.getGood_sum();
            if (Double.parseDouble(goodsInfoBean.getDiscountprice()) == 0) {
                price += goodsInfoBean.getGood_sum() * Double.parseDouble(goodsInfoBean.getMarketprice());
            } else {
                price += goodsInfoBean.getGood_sum() * Double.parseDouble(goodsInfoBean.getDiscountprice());
            }

        }

        total_price = format1(price);
        total_num = num;
        tvTotalGoodsNum.setText(total_num + "");
        tvShopCarPrice.setText("¥" + total_price);
        tvCarTotalNum.setText("购物车(共" + carList.size() + "件商品)");
        if (total_num == 0) {
            viewShopCarBg.setBackgroundResource(R.drawable.round_hui_bg);
            tvToSettleAccounts.setBackgroundResource(R.color.color_999999);
            tvShopCarPrice.setText(getResources().getText(R.string.unselected_goods));
            tvShopCarPrice.setTextSize(14);
            tvShopCarPrice.setTextColor(getResources().getColor(R.color.color_999999));
            tvTotalGoodsNum.setVisibility(View.INVISIBLE);
        } else {
            if (tvTotalGoodsNum.getVisibility() != View.VISIBLE) {
                tvTotalGoodsNum.setVisibility(View.VISIBLE);
                viewShopCarBg.setBackgroundResource(R.drawable.round_orange_bg);
                tvToSettleAccounts.setBackgroundResource(R.color.color_FB9129);

                tvShopCarPrice.setTextSize(17);
                tvShopCarPrice.setTextColor(getResources().getColor(R.color.color_F93331));
            }
        }



        //活动是否显示
        if (UtilsData.getPreference(mContext, "activity").getBoolean("is_69")&&!SHOPID_69_NO.contains(shopID)) {
            tvActivityManJian.setVisibility(View.VISIBLE);
            if (total_num > 0) {
                if (price < 69) {
                    String cha = format1(69 - price);
                    String hint = "还差" + cha + "任减1件商品（至少选择5件商品）";
                    SpannableString spannableString = new SpannableString(hint);
                    //设置颜色
                    spannableString.setSpan(new ForegroundColorSpan(Color.parseColor("#F93331")), 2, 2 + cha.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
                    tvActivityManJian.setText(spannableString);
                } else if (total_num < 5) {
                    int cha = 5 - total_num;
                    SpannableString spannableString = new SpannableString("还差" + cha + "件商品");
                    //设置颜色
                    spannableString.setSpan(new ForegroundColorSpan(Color.parseColor("#F93331")), 2, 4, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
                    tvActivityManJian.setText(spannableString);
                } else {

                    tvActivityManJian.setText("已随机减免1件商品，可在结算页面查看");
                }
            } else {
                tvActivityManJian.setText("满69任减1件商品");
            }
        } else {
            tvActivityManJian.setVisibility(View.GONE);
            tvActivity.setVisibility(View.GONE);
            tvYouhuiNum.setVisibility(View.GONE);
        }
    }

    public Animation shakeAnimation(int CycleTimes) {
        Animation animation = new ScaleAnimation(1.0f, 1.2f, 1.0f, 1.2f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
//        Animation translateAnimation = new TranslateAnimation(10, 10, 10, 10);
//        translateAnimation.setInterpolator(new CycleInterpolator(CycleTimes));
//        translateAnimation.setDuration(1000);
        animation.setInterpolator(new CycleInterpolator(CycleTimes));
        animation.setDuration(800);
        return animation;
    }


    /*
     * 方法名：startTranslationAnimation()
     * 功    能：开启平移动画
     * 参    数：无
     * 返回值：无
     */
    private void startTranslationAnimation() {
//        TranslateAnimation startTranslateAnim = new TranslateAnimation(0, 0, -height, 0);
//        startTranslateAnim.setDuration(300);
//        llCar.startAnimation(startTranslateAnim);
        //设置动画，从自身位置的最下端向上滑动了自身的高度，持续时间为500ms
        final TranslateAnimation ctrlAnimation = new TranslateAnimation(
                TranslateAnimation.RELATIVE_TO_SELF, 0, TranslateAnimation.RELATIVE_TO_SELF, 0,
                TranslateAnimation.RELATIVE_TO_SELF, 1, TranslateAnimation.RELATIVE_TO_SELF, 0);
        ctrlAnimation.setDuration(300);     //设置动画的过渡时间
        llCar.postDelayed(new Runnable() {
            @Override
            public void run() {
                tvCarTotalNum.setText("购物车(共" + carList.size() + "件商品)");
                viewBgBlack.setVisibility(View.VISIBLE);
                llCar.setVisibility(View.VISIBLE);
                llCar.startAnimation(ctrlAnimation);
            }
        }, 300);

    }

    /*
     * 方法名：endTranslationAnimation()
     * 功    能：关闭平移动画
     * 参    数：无
     * 返回值：无
     */
    private void endTranslationAnimation() {
//        TranslateAnimation endTranslateAnim= new TranslateAnimation(0, 0, 0, -height);
//        endTranslateAnim.setDuration(300);
//        llCar.startAnimation(endTranslateAnim);

//        设置动画，从自身位置的最下端向上滑动了自身的高度，持续时间为500ms
        final TranslateAnimation ctrlAnimation = new TranslateAnimation(
                TranslateAnimation.RELATIVE_TO_SELF, 0, TranslateAnimation.RELATIVE_TO_SELF, 0,
                TranslateAnimation.RELATIVE_TO_SELF, 0, TranslateAnimation.RELATIVE_TO_SELF, 1);
        ctrlAnimation.setDuration(300);     //设置动画的过渡时间
        llCar.postDelayed(new Runnable() {
            @Override
            public void run() {
                viewBgBlack.setVisibility(View.GONE);
                llCar.setVisibility(View.GONE);
                llCar.startAnimation(ctrlAnimation);
            }
        }, 300);

    }

    @Override
    protected boolean isUseFullScreenMode() {
        return true;
    }

    @Override
    protected void onDestroy() {
        if (null != dialog) {
            if (dialog.isShowing()) {
                dialog.dismiss();
            }
            dialog = null;
        }
        if (null != carPopupWindow) {
            if (carPopupWindow.isShowing()) {
                carPopupWindow.dismiss();
            }
            carPopupWindow = null;
        }
        bitmap = null;
        super.onDestroy();
    }

    /*
     * 方法名：initOnPreDrawListener()
     * 功    能：初始化viewTreeObserver事件监听,重写OnPreDrawListener获取组件高度
     * 参    数：无
     * 返回值：无
     */
    private void initOnPreDrawListener() {
        final ViewTreeObserver viewTreeObserver = this.getWindow().getDecorView().getViewTreeObserver();
        viewTreeObserver.addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
            @Override
            public boolean onPreDraw() {
                height = llCar.getMeasuredHeight();
//                int width = mText1.getMeasuredWidth();
                Log.e("TAG", "高：" + height);
                // 移除OnPreDrawListener事件监听
                getWindow().getDecorView().getViewTreeObserver().removeOnPreDrawListener(this);
                //获取完高度后隐藏控件
                llCar.setVisibility(View.GONE);
                return true;
            }
        });
    }

    @Override
    protected void onStart() {
        super.onStart();
        mPresenter.shopCarList(shopID, "0");
    }

    /**
     * 分享到小程序
     */
    public void shareToXcc(String imgPath, String title, String des, String shopId) {
        Glide.with(this)
                .asBitmap()
                .load(imgPath).into(new SimpleTarget<Bitmap>() {
            @Override
            public void onResourceReady(@NonNull Bitmap resource, @Nullable Transition<? super Bitmap> transition) {
                //   bitmap = resource;
                bitmap = compressImage(resource);
                UMMin umMin = new UMMin("http://www.weixin.com");
                //兼容低版本的网页链接
                UMImage image = new UMImage(ShopActivity.this, bitmap);
                //image.compressStyle = UMImage.CompressStyle.SCALE;
                image.compressStyle = UMImage.CompressStyle.QUALITY;

                umMin.setThumb(image);
                // 小程序消息封面图片
                umMin.setTitle(title);
                // 小程序消息title
                umMin.setDescription(des);
                // 小程序消息描述
                umMin.setPath(Constants.LS_GOODSINFO + shopId);//小程序页面路径
                umMin.setUserName(Constants.XCCID);
                // 小程序原始id,在微信平台查询
                new ShareAction(ShopActivity.this)
                        .withMedia(umMin)
                        .setPlatform(SHARE_MEDIA.WEIXIN)
                        .setCallback(shareListener).share();

            }
        });

    }

    public static Bitmap compressImage(Bitmap bitmap) {
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        //质量压缩方法，这里100表示不压缩，把压缩后的数据存放到baos中
        bitmap.compress(Bitmap.CompressFormat.JPEG, 60, baos);
        int options = 60;
        //循环判断如果压缩后图片是否大于50kb,大于继续压缩
        while (baos.toByteArray().length / 1024 > 500) {
            //清空baos
            baos.reset();
            bitmap.compress(Bitmap.CompressFormat.JPEG, options, baos);
            options -= 10;//每次都减少10
        }
        //把压缩后的数据baos存放到ByteArrayInputStream中
        ByteArrayInputStream isBm = new ByteArrayInputStream(baos.toByteArray());
        //把ByteArrayInputStream数据生成图片
        Bitmap newBitmap = BitmapFactory.decodeStream(isBm, null, null);
        return newBitmap;
    }

    public static int getBitmapSize(Bitmap bitmap) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {    //API 19
            return bitmap.getAllocationByteCount();
        }
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR1) {//API 12
            return bitmap.getByteCount();
        }
        // 在低版本中用一行的字节x高度
        return bitmap.getRowBytes() * bitmap.getHeight();
    }

    private UMShareListener shareListener = new UMShareListener() {
        /**
         * @descrption 分享开始的回调
         * @param platform 平台类型
         */
        @Override
        public void onStart(SHARE_MEDIA platform) {
            Log.e("platform", "点击分享" + platform.getName());
        }

        /**
         * @descrption 分享成功的回调
         * @param platform 平台类型
         */
        @Override
        public void onResult(SHARE_MEDIA platform) {
            // Toast.makeText(mActivity,"成功了",Toast.LENGTH_LONG).show();
        }

        /**
         * @descrption 分享失败的回调
         * @param platform 平台类型
         * @param t 错误原因
         */
        @Override
        public void onError(SHARE_MEDIA platform, Throwable t) {
            //Toast.makeText(ShopActivity.this,"失败"+t.getMessage(),Toast.LENGTH_LONG).show();
        }

        /**
         * @descrption 分享取消的回调
         * @param platform 平台类型
         */
        @Override
        public void onCancel(SHARE_MEDIA platform) {
            // Toast.makeText(ShopActivity.this,"取消了",Toast.LENGTH_LONG).show();

        }
    };

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        UMShareAPI.get(this).onActivityResult(requestCode, resultCode, data);
    }

    /*
    加载指定URL的图片并设置到targetView, 取主色调palete
 */
//    public void loadAndPalette(Context context, String url, ImageView targetView, TextView textView) {
//        Glide.with(context).load(url)
//                .listener(GlidePalette.with(url)
//                        .use(GlidePalette.Profile.VIBRANT)
//                        .intoBackground(textView, GlidePalette.Swatch.RGB)
//                        .intoTextColor(textView, GlidePalette.Swatch.BODY_TEXT_COLOR)
//                        .crossfade(true)
//                )
//                .into(targetView);
//    }

    /**
     * 根据百分比改变颜色透明度
     */
    public int changeAlpha(int color, float fraction) {
        int red = Color.red(color);
        int green = Color.green(color);
        int blue = Color.blue(color);
        int alpha = (int) (Color.alpha(color) * fraction);
        return Color.argb(alpha, red, green, blue);
    }

    /**
     * 设置白色系统状态栏
     */
    private void setLightTitleSysBg() {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            try {
                //设置状态栏文字颜色及图标为深色
                getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
                StatusBarUtil.setStatusBarColor(this, R.color.color_FFFFFF);
            } catch (Exception e) {
                return;
            }

        }
    }

    /**
     * 设置黑色系统状态栏
     */
    private void setDarkTitleSysBg() {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            try {
                // 如果亮色，设置状态栏文字为黑色
                getWindow().getDecorView().setSystemUiVisibility(
                        View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_STABLE);
                StatusBarUtil.setStatusBarColor(this, R.color.color_333333);
            } catch (Exception e) {
                return;
            }
        }
    }

    private void clearState(ImageView star01, ImageView star02, ImageView star03, ImageView star04, ImageView star05,String starnum) {
        star01.setVisibility(View.GONE);
        star02.setVisibility(View.GONE);
        star03.setVisibility(View.GONE);
        star04.setVisibility(View.GONE);
        star05.setVisibility(View.GONE);

        switch (starnum){
            case "1":
                star01.setVisibility(View.VISIBLE);
                break;
            case "2":
                star01.setVisibility(View.VISIBLE);
                star02.setVisibility(View.VISIBLE);
                break;
            case "3":
                star01.setVisibility(View.VISIBLE);
                star02.setVisibility(View.VISIBLE);
                star03.setVisibility(View.VISIBLE);
                break;
            case "4":
                star01.setVisibility(View.VISIBLE);
                star02.setVisibility(View.VISIBLE);
                star03.setVisibility(View.VISIBLE);
                star04.setVisibility(View.VISIBLE);
                break;
            case "5":
                star01.setVisibility(View.VISIBLE);
                star02.setVisibility(View.VISIBLE);
                star03.setVisibility(View.VISIBLE);
                star04.setVisibility(View.VISIBLE);
                star05.setVisibility(View.VISIBLE);
                break;
        }
    }

}
